package com.puyuba.puyuba.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.puyuba.puyuba.R;
import com.puyuba.puyuba.SkinApplication;
import com.puyuba.puyuba.bean.NeedBean;
import com.puyuba.puyuba.bean.QRcodeBean;
import com.puyuba.puyuba.network.UserApi;
import com.pyb.java.cache.CacheUserInfo;
import com.pyb.java.commonutil.ImageHelper;
import com.pyb.java.commonutil.ToastHelper;
import com.pyb.java.network.RequestBodyUtil;
import com.pyb.java.network.ResponseEntity;
import com.pyb.java.network.RetrofitManger;
import com.pyb.java.network.observers.ResponseObserve;
import com.pyb.java.network.scheduler.RxSchedulers;

import java.util.HashMap;

import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;

/**
 * 联系管理员dialog
 */

public class ContactAdminDialog extends Dialog {

    private RelativeLayout rlBg;
    private ImageView ivClose;
    private TextView count;
    private ImageView ivQrcode;

    public ContactAdminDialog(Context context) {
        super(context, R.style.ContactDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_contact_admin_layout);
        initView();
        //初始化界面控件的事件
        initEvent();
        iosPayImage();
    }

    //支付弹窗
    public void iosPayImage() {
        RetrofitManger.getInstance().createService(UserApi.class)
                .iosPayImage()
                .compose(RxSchedulers.<ResponseEntity<QRcodeBean>>applySchedulers())
                .subscribe(new ResponseObserve<QRcodeBean>(){

                    @Override
                    public void onSuccess(ResponseEntity<QRcodeBean> responseEntity) {
                        Glide.with(SkinApplication.getInstance()).load(responseEntity.getData().getFilePath()).into(ivQrcode);
                    }

                    @Override
                    public void onFail(String errorMsg) {
                        if (errorMsg != null&&!errorMsg.equals("")){
                            ToastHelper.show(errorMsg);
                        }else {
                            ToastHelper.show("服务器繁忙，请稍后再试");
                        }
                    }

                    @Override
                    public void onSubscribeStart(@NonNull Disposable disposable) { }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                    }

                });
    }
    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        rlBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }
    /**
     * 设置确定取消按钮的回调
     */
    public OnClickBottomListener onClickBottomListener;
    public ContactAdminDialog setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        return this;
    }

    public void setText(int serviceNum) {
        count.setText(""+serviceNum);
    }

    public interface OnClickBottomListener{

        public void commit(String currentEdu, String targetEdu, String time, int easy);

    }
    private void initView() {
        rlBg = (RelativeLayout) findViewById(R.id.rl_bg);
        ivClose = (ImageView) findViewById(R.id.iv_close);
        count = (TextView) findViewById(R.id.count);
        ivQrcode = (ImageView) findViewById(R.id.iv_qrcode);


    }


}